package com.allwees.bs.module.pms.vo.excel;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.allwees.bs.core.model.util.PhotosStr;
import com.allwees.bs.core.modelbase.importdata.ImportDataBean;
import com.allwees.bs.module.pms.entity.Product;
import com.allwees.bs.module.pms.entity.Sku;
import com.allwees.core.common.constant.EStatus;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.List;

/**
 * 一步导入Product和Sku（参考Wish模板）
 *
 * @author yangylsky
 * @since 2020-03-03
 */
@Data
public class ImportProductSkuBean implements ImportDataBean, PhotosStr {
    public String getProductCustomNo() {
        return null;
    }

    public String getProductName() {
        return null;
    }

    public String getDescription() {
        return null;
    }

    public String getKeywords() {
        return null;
    }

    public String getMainPhoto() {
        return null;
    }

    public String getSkuCustomNo() {
        return null;
    }

    public String getColor() {
        return null;
    }

    public BigDecimal getRetailPrice() {
        return null;
    }

    public BigDecimal getShippingPrice() {
        return null;
    }

    public BigDecimal getOriginalPrice() {
        return null;
    }

    public String getCurrency() {
        return null;
    }

    public String getShippingArrivalDesc() {
        return null;
    }

    public Integer getShippingMinDays() {
        return null;
    }

    public Integer getShippingMaxDays() {
        return null;
    }

    //    public String getSkuUuid(){return null;}
    public String getSize() {
        return null;
    }

    public String getShippingCurrency() {
        return null;
    }

    public Float getWeight() {
        return null;
    }

    public Integer getQuantity() {
        return null;
    }

    public String getWeightUnit() {
        return null;
    }

    //    public String getSkuImage(){return null;}
    public String getOption1Name() {
        return null;
    }

    public String getOption2Name() {
        return null;
    }

    public String getOption3Name() {
        return null;
    }


    public void setProductCustomNo(String no) {
    }

    public void setDescription(String desc) {
    }

    public void setKeywords(String word) {
    }

    public void setProductName(String productName) {
    }

    public void setSkuCustomNo(String no) {
    }

    public void setColor(String color) {
    }

    public void setSize(String size) {
    }

    public void setMainPhoto(String photo) {
    }

    public void setOption1Name(String str) {
    }

    public void setOption2Name(String str) {
    }

    public void setOption3Name(String str) {
    }

    public void setOriginalPrice(BigDecimal price) {
    }

    public void setRetailPrice(BigDecimal price) {
    }

    public void setShippingPrice(BigDecimal price) {
    }

    @JsonIgnore
    @JSONField(serialize = false)
    protected transient String photoStr;

    @JsonIgnore
    @JSONField(serialize = false)
    protected transient String storeUuid;

    @JsonIgnore
    @JSONField(serialize = false)
    protected transient String categoryNo;

    @JsonIgnore
    @JSONField(serialize = false)
    protected List<String> extraPhotos = Lists.newArrayListWithCapacity(10);

    public void addExtraPhoto(String photo) {
        if (extraPhotos.size() >= 10) {
            return;
        }
        extraPhotos.add(photo);
    }

    @Override
    public String getPhotosStr() {
        photoStr = StringUtils.join(extraPhotos, ',');
        return photoStr;
    }

    @Override
    public void setPhotosStr(String photoStr) {
        if (StringUtils.isNotBlank(photoStr)) {
            extraPhotos = Splitter.on(',').omitEmptyStrings().trimResults().splitToList(photoStr);
        }
    }

    @Override
    public void completion() {
        this.setProductCustomNo(StringUtils.trim(getProductCustomNo()));
        this.setDescription(StringUtils.trim(getDescription()));
        this.setKeywords(StringUtils.trim(getKeywords()));
        this.setProductName(StringUtils.trim(getProductName()));
        this.setSkuCustomNo(StringUtils.trim(getSkuCustomNo()));
        this.setColor(StringUtils.trim(getColor()));
        this.setSize(StringUtils.trim(getSize()));
    }

    public Product toProduct() {
        Product product = new Product();
        product.setStatus(EStatus.CREATED.value());
        product.setStoreUuid(getStoreUuid());
        product.setCategoryNo(getCategoryNo());
        product.setCustomNo(getProductCustomNo());
        product.setName(getProductName());
        product.setDescription(getDescription());
        product.setKeywords(getKeywords());
        product.setCurrency(getCurrency());
        product.setOriginalPrice(getOriginalPrice());
        product.setRetailPrice(getRetailPrice());
        product.setShippingArrivalDesc(getShippingArrivalDesc());
        product.setShippingMinDays(getShippingMinDays());
        product.setShippingMaxDays(getShippingMaxDays());
        product.setMainPhoto(getMainPhoto());
        //给一个初始值
        product.setScore(Product.DEFAULT_SCORE);
        product.attachRandomSales();
        String photosStr = getPhotosStr();
        product.setPhotosStr(StringUtils.isNotBlank(photosStr) ? photosStr : getMainPhoto());
        return product;
    }

    public Sku toSku() {
        Sku sku = new Sku();
        sku.setCustomNo(getSkuCustomNo());
        sku.setColor(StringUtils.isNotBlank(getColor()) ? getColor() : "default");
        sku.setSize(StringUtils.isNotBlank(getSize()) ? getSize() : "default");
        sku.setCurrency(getCurrency());
        sku.setRetailPrice(getRetailPrice());
        sku.setOriginalPrice(getOriginalPrice());
        sku.setShippingCurrency(getShippingCurrency());
        sku.setShippingPrice(getShippingPrice() != null ? getShippingPrice() : BigDecimal.ZERO);
        sku.setQuantity(getQuantity());
        sku.setWeight(getWeight());
        sku.setWeightUnit(getWeightUnit());
        return sku;
    }

    public void initData() {
    }
}
